﻿using System.ComponentModel;
using System.Runtime.Serialization;
using Roniz.WCF.P2P.Sync.Messages.BusinessLogic;

namespace Roniz.WCF.P2P.ApplicationTester.Messages
{
    [DataContract]
    public class MyUserUpdateState : BusinessLogicMessageBase, INotifyPropertyChanged
    {
        #region members
        private string name;
        private string data;
        private MyFullPresenceInfo myFullPresenceInfo;
        private bool isOwnPeerData;

        #endregion

        #region events

        #region Implementation of INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #endregion

        #region properties

        /// <summary>
        /// determine if this instance represent data generated by own peer and not from synchronized peer
        /// this is also the reason that this property does not have [DataMember] attribute  - it should not transmit to the other peers
        /// </summary>
        public bool IsOwnPeerData
        {
            get
            {
                return isOwnPeerData;
            }
            set
            {
                if (isOwnPeerData != value)
                {
                    isOwnPeerData = value;
                    InvokePropertyChanged("IsOwnPeerData");
                }
            }
        }

        [DataMember]
        public string Name
        {
            get { return name; }
            set
            {
                if (name != value)
                {
                    name = value;
                    InvokePropertyChanged("Name");
                }
            }
        }

        [DataMember]
        public string Data
        {
            get { return data; }
            set
            {
                if (data != value)
                {
                    data = value;
                    InvokePropertyChanged("Data");
                }
            }
        }

        public MyFullPresenceInfo FullPresenceInfo
        {
            get { return myFullPresenceInfo; }
            set
            {
                if (myFullPresenceInfo != value)
                {
                    myFullPresenceInfo = value;
                    InvokePropertyChanged("FullPresenceInfo");
                }
            }
        }

        #endregion

        #region methods

        public override string ToString()
        {
            return string.Format("Name: {0} , Data: {1}",Name ?? "null",Data ?? "null");
        }

        #region Implementation of INotifyPropertyChanged

        public void InvokePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
        #endregion
    }
}